package nju.mscs.server.businessLogic;

import nju.mscs.data.object.Database;
import nju.mscs.data.object.Date;
import nju.mscs.data.object.User;
import nju.mscs.data.object.VipConsumer;

public class AM implements AccountManager{
	private String id;
	private Database db;
	public AM(){
		db=Controller.sumDB;
	}
	public String[] createNewUser(String name,String password,String position,String adress){
		int pos=-1;
		if(position.equals("收银员"))
			pos=User.CASHIER;
		else if(position.equals("分店经理"))
			pos=User.SHOP_MANAGER;
		else if(position.equals("总经理"))
			pos=User.GENERAL_MANAGER;
		else if(position.equals("系统管理员"))
			pos=User.SYSTEM_MANAGER;
		String id=createUserID(pos);
		db.addUser(name, password, id,pos,Integer.parseInt(adress));
		String[] result={id,name,position,password};
		return result;
	}
	public boolean deleteUser(String id){
		return db.deleteUser(id);
	}
	private String createUserID(int position){
		String id=""+(db.getAmountOfUser()*10+position+1000);//生成id,有待修改
		return id;
	}

	public boolean changeUser(String[] infor) {
		User user=db.searchUserById(infor[0]);
		user.setName(infor[1]);
		user.setPassword(infor[2]);
		System.out.println("AS:"+infor[2]);
		int type=-1;
		if(infor[3].equals("收银员"))
			type=User.CASHIER;
		else if(infor[3].equals("分店经理"))
			type=User.SHOP_MANAGER;
		else if(infor[3].equals("总经理"))
			type=User.GENERAL_MANAGER;
		user.setType(type);
		// TODO Auto-generated method stub
		return true;
	}
}
